
import Vue from "vue";
import Vuex from 'vuex'
Vue.use(Vuex);

// 跟vuex相关
import { addLocalGoods,getLocalTotal,updateLocalGoods,deleteLocalGoods } from "../../common/localStorageHelper.js";
const store = new Vuex.Store({    
    state: {
      count: 0
    },
    getters: {
        getTotalCounts: state => {
        //   return state.count;
        if(state.count>0){
            return state.count;
        }else{
           return getLocalTotal();
        }
        }
      },
    mutations: {
      addGoods (state,goods) {
        state.count=addLocalGoods(goods);
        // console.log(addLocalGoods);
      },
      updateGoods(state,goods){
        state.count = updateLocalGoods(goods);
      },
      deleteGoodsById (state,goodsId){
        state.count = deleteLocalGoods(goodsId);
      }
    }
  })

  export {store}

